package com.hyc.DataStructure.sort;

/**
 * @projectName: DataStructure
 * @package: com.hyc.DataStructure.sort
 * @className: insertSrot
 * @author: 冷环渊 doomwatcher
 * @description: TODO
 * @date: 2022/1/13 0:57
 * @version: 1.0
 */
public class insertSrot {
    public static void main(String[] args) {
        int[] arr = {34, 101, 89, 1};
        int[] test = new int[800000];
        //测试数据
        for (int i = 0; i < 800000; i++) {
            test[i] = (int) (Math.random() * 800000);
        }
        long time = System.currentTimeMillis();
        insertSort(test);
        long end = System.currentTimeMillis();
        long t = ((end - time) / 1000);
        System.out.println("一共用时 " + t + "秒");
    }

    public static void insertSort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            int insertindex = i - 1;
            int insertvar = arr[i];
            while (insertindex >= 0 && arr[insertindex] > insertvar) {
                arr[insertindex + 1] = arr[insertindex];
                insertindex--;
            }
            arr[insertindex + 1] = insertvar;
        }
    }
}
